/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <filesystem/String.hpp>
#include <textstream/File.h>
#include "Log.h"
#include <stdio.h>	//for printf

#ifdef ANDROID_NDK
#include <android/log.h>
#endif

#ifdef SAMSUNG_VERSION
#include <FBase.h>
#endif

namespace liba
{
namespace logs
{

template<class Sym>
class File : public Log<Sym>
{
	int error_counter;
	int warning_counter;
	textstream::File<Sym> file;
public:
	explicit File(const filesystem::String & fname, filesystem::File::Mode mode = filesystem::File::WRITE )
	:	error_counter( 0 ),
		warning_counter( 0 ),
		file( fname, mode )
	{}
	virtual ~File()
	{}
	virtual void print(const Sym * begin, const Sym * end)
	{
		file.print( begin, end );
		file.flush();
	}
	virtual void flush()
	{
		file.flush();
	}
	virtual void inc_error_counter()
	{
		++error_counter;
	}
	virtual void inc_warning_counter()
	{
		++warning_counter;
	}
};

template<class Sym>
class Dummy : public Log<Sym>
{
public:
	explicit Dummy()
	{
#ifdef ANDROID_NDK
	    __android_log_print(ANDROID_LOG_INFO, "APK", "hello from console log");
#endif
	}
	virtual ~Dummy()
	{}
	virtual void print(const Sym * begin, const Sym * end)
	{
#ifdef ANDROID_NDK
		std::string str(begin, end);
		__android_log_print(ANDROID_LOG_INFO, "APK", "%s", str.c_str());
#else
#ifdef SAMSUNG_VERSION
		std::string str(begin, end);
		AppLog("%s", str.c_str());
#else
		std::string str(begin, end);
		printf("%s", str.c_str());
#endif
#endif
	}
	virtual void flush(){}
	virtual void inc_error_counter(){}
	virtual void inc_warning_counter(){}
};
	
} // namespace logs
} // namespace liba

using namespace liba;
